import { Message } from 'element-ui'
let errorPage = {}

errorPage.install = function (Vue, options) {
  // 接受错误的error
  Vue.catchError = Vue.prototype.$catchError = function (error, ...funcs) {
    console.log('11111111111111', error.response);
    if (error.response) {
      Message({
        // duration: 0,
        showClose: true,
        message: `错误信息：${error.response.data}`,
        type: 'error'
      })
      return
    }
    // debugger
    if (error.response.status === 401) {
      // 返回登陆页
    } else {
      // router.push({path: `/${error.response.status}`})
    }
    funcs.forEach(func => func())
  }
  // 返回正确接收返回非1的错误码
  Vue.codeError = Vue.prototype.$codeError = function (res, ...funcs) {
    Message({
      // duration: 0,
      showClose: true,
      message: `错误信息：${res.data.msg}`,
      type: 'error'
    })
    funcs.forEach(func => func())
  }
}
export default errorPage
